package com.act.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import com.act.dao.IEmployeeDao;
import com.act.domain.Employee;
import com.act.dto.PagerDTO;
import com.act.service.api.IEmployeeService;
import com.act.vo.PagerVo;

@Service
public class EmployeeServiceImpl implements IEmployeeService{

	@Resource
	IEmployeeDao employeeDao;
	
	@Override
	public List<Employee> getEmployeesByEmployeeIdOrName(int status,String jobnum,String name) {
		return employeeDao.getEmployeesByEmployeeIdOrName(status,jobnum, name);
	}


	@Override
	public void add(Employee employee) {
		employeeDao.add(employee);
	}

	@Override
	public void update(Employee employee) {
		employeeDao.update(employee);
	}

	@Override
	public void delete(int id) {
		// TODO Auto-generated method stub
		employeeDao.delete(id);
	}

	@Override
	public Employee login(@Param("jobnum")String jobnum,@Param("password")String password) {
		return employeeDao.login(jobnum, password);
	
	}

	@Override
	public Employee getEmployeeById(@Param("id")int id) {
		return employeeDao.getEmployeeById(id);
	}

	@Override
	public PagerVo<Map> getAll(@Param("pagerDTO")PagerDTO pagerDTO) {
		int startIndex = pagerDTO.getStartIndex();
		int endIndex = pagerDTO.getEndIndex();
		List<Map> list = employeeDao.getAll(startIndex, endIndex);
		int totalCounts = employeeDao.getCounts();
		PagerVo<Map> pagerVo = new PagerVo<>(pagerDTO.getPageIndex(),pagerDTO.getPageSize(),totalCounts,list);
		return pagerVo;
	}

	@Override
	public PagerVo<Map> getByDepartId(@Param("pagerDTO")PagerDTO pagerDTO, @Param("departId")int departId) {
		int startIndex = pagerDTO.getStartIndex();
		int endIndex = pagerDTO.getEndIndex();
		List<Map> list = employeeDao.getByDepartId(startIndex, endIndex,departId);
		int totalCounts = employeeDao.getCountsByCondition(departId, 5);
		PagerVo<Map> pagerVo = new PagerVo<>(pagerDTO.getPageIndex(),pagerDTO.getPageSize(),totalCounts,list);
		return pagerVo;
	}



	@Override
	public PagerVo<Map> getByStatus(@Param("pagerDTO")PagerDTO pagerDTO, @Param("status")int status) {
		int startIndex = pagerDTO.getStartIndex();
		int endIndex = pagerDTO.getEndIndex();
		List<Map> list = employeeDao.getByStatus(startIndex, endIndex,status);
		int totalCounts = employeeDao.getCountsByCondition(0, status);
		PagerVo<Map> pagerVo = new PagerVo<>(pagerDTO.getPageIndex(),pagerDTO.getPageSize(),totalCounts,list);
		return pagerVo;
	}

	@Override
	public List<Employee> getAllList() {
		return employeeDao.getAllList();
	}


	@Override
	public void updatePWD(Employee employee) {
		employeeDao.updatePWD(employee);
	}

}
